<?php

/**
 * 点评管理
 */
class ReviewsAction extends globalAction {
    private $reviewsDao, $innDao, $myInn;
    
    public function _initialize() {
		parent::_initialize();
        parent::_loginRequire();
        $this->reviewsDao = D('InnReviews');
        $this->innDao = D('Inn');
        
        $field = array(
            $this->innDao->_map['id'] => 'id',
            $this->innDao->_map['name'] => 'name'
        );
        $myInnList = $this->innDao
            ->field($field)
            ->where(array(
                $this->innDao->_map['menuId'] => 585,
                $this->innDao->_map['uid'] => __USERID__
            ))
            ->select();
        if(!empty($myInnList)) {
            $this->myInn = makearray($myInnList, 'id', 'name');
            $this->assign('myInn', $this->myInn);
        }
	}
    
    public function index() {

        $conditions[$this->reviewsDao->_map['menu_id']] = 604;
        $conditions[$this->reviewsDao->_map['product_id']] = array('in',array_keys($this->myInn));
        
        $reviewsList = $this->reviewsDao
            ->field($this->reviewsDao->_map_flip)
            ->where($conditions)
            ->order($this->reviewsDao->_map['msg_time'])
            ->select();
        $this->assign('reviewsList', $reviewsList);

        $this->display();
    }
    
    public function details() {
        $rv_id = intval($_GET['id']);
        if(empty($rv_id)) parent::_message('error', '未指定点评内容ID');
        
        $conditions[$this->reviewsDao->_map['rv_id']] = $rv_id;
        $conditions[$this->reviewsDao->_map['menu_id']] = 604;
        $conditions[$this->reviewsDao->_map['product_id']] = array('in',array_keys($this->myInn));
        
        $reviews = $this->reviewsDao
            ->field($this->reviewsDao->_map_flip)
            ->where($conditions)
            ->find();
        $this->assign('reviews', $reviews);

        $this->display();
    }
}